/**
 * 房间中玩家數據類
 * @author LuoDong
 * @email luo4521@online.net.tw
 */
package com.addcn.texas.data
{		
	import com.addcn.texas.inter.IUser;
	
	public class  GameUser extends User 
	{		
		private var _chip : uint;  //玩家籌碼				
		private var _bet : uint;  //玩家当前下注籌碼		
		private var _sit : int;  //玩家座位號		
		private var _poker : Array; //玩家私有撲克
		
		
		function GameUser( ) : void {}		
		
		override public function initialize(r_data:Object):void 
		{
			super.initialize(r_data);
			this._chip = parseFloat(r_data["chip"]);			
			this._sit = parseInt(r_data["sit"]);			
		}
		
		override public function getUserInfo():Object 
		{
			var _obj = super.getUserInfo();
			_obj["sit"] = _sit;
			_obj["chip"] = _chip;
			return _obj;
		}
		
		/**
		 * 设置玩家筹码
		 */
		public function set chip(r_chip : uint) : void
		{
			this._chip = r_chip;
		}
		
		/**
		 * 获取玩家筹码
		 */
		public function get chip() : uint
		{
			return this._chip;
		}
						
		/**
		 * 设置玩家座位号 
		 */
		public function set sit(r_sit : int) : void
		{
			this._sit = r_sit;
		}
		
		/**
		 * 获取玩家座位号
		 */
		public function get sit() : int
		{
			return this._sit;
		}

		/**
		 * 獲取玩家下注籌碼
		 */
		public function get bet() : uint
		{
			return this._bet;
		}
		
		/**
		 * 设置玩家下注筹码
		 */
		public function set bet(r_bet : uint) : void
		{	
			this._bet = r_bet;			
		}
		
		/**
		 * 兌換籌碼
		 * @param	r_chip int 
		 * @return int
		 */
		public function convertChip(r_chip : uint) : int
		{
			if(r_chip < this.gold){				
				this.gold -= r_chip;	
				this._chip = r_chip;
			}else {
				this._chip = this.gold;
				this.gold = 0;
			}
			return this._chip;
		}
		
		/**
		 * 將籌碼退回到點數
		 */
		public function resetChip() : void
		{			
			if (this._chip > 0 ) {
				this.gold += this._chip;				
			}
			this._chip = 0;
		}
		
		/**
		 * 设置扑克牌
		 */
		public function set poker(r_arr : Array) : void
		{
			this._poker =  r_arr;
		}
		
		/**
		 * 获取玩家扑克牌
		 */
		public function get poker() : Array
		{
			return this._poker;
		}
		
		/**
		 * 清除玩家扑克牌
		 */
		public function clearPoker() : void
		{
			this._poker = null;
		}
			
		/**
		 * 銷毀數據
		 */
		override  public function destroy() : void
		{								
			super.destroy();
		}
		
		
	}
	
}
